package masterjava.common.type;

import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for FaultInfoType complex type.
 * <p/>
 * <p>The following schema fragment specifies the expected content contained within this class.
 * <p/>
 * <pre>
 * &lt;complexType name="FaultInfoType">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="detail" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         &lt;element name="context" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/>
 *       &lt;/sequence>
 *       &lt;attribute name="code" use="required" type="{http://www.w3.org/2001/XMLSchema}int" />
 *       &lt;attribute name="type" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "FaultInfoType", namespace = "http://type.common.masterjava", propOrder = {
        "detail",
        "context"
})
public class FaultInfoType {

    public FaultInfoType() {
    }

    public FaultInfoType(String type) {
        this.type = type;
    }

    protected String detail;
    protected List<String> context;

    @XmlAttribute(required = true)
    protected int code;

    @XmlAttribute(required = true)
    protected String type;

    @XmlAttribute(required = true)
    protected String source;

    @XmlAttribute
    protected int vcsRevision;

    public String getDetail() {
        return detail;
    }

    public void setDetail(String value) {
        this.detail = value;
    }

    public List<String> getContext() {
        if (context == null) {
            context = new ArrayList<String>();
        }
        return this.context;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int value) {
        this.code = value;
    }

    public String getType() {
        return type;
    }

    public void setType(String value) {
        this.type = value;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public int getVcsRevision() {
        return vcsRevision;
    }

    public void setVcsRevision(int vcsRevision) {
        this.vcsRevision = vcsRevision;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("{type=").append(type);
        if (detail != null) {
            sb.append("\n detail='").append(detail).append('\'');
        }
        if (CollectionUtils.isNotEmpty(context)) {
            sb.append("\n context=").append(context.toString());
        }
        if (code != 0) {
            sb.append("\n code=").append(code);
        }
        sb.append('}');
        return sb.toString();
    }
}
